import request from '../utils/request';  // request 是 demo 项目脚手架中提供的一个做 http 请求的方法，是对于 fetch 的封装，返回 Promise
import {getDetails} from '../services/getdetails'
const delay = (millisecond) => {
  return new Promise((resolve) => {
    setTimeout(resolve, millisecond);
  });
};

export default {
  namespace: 'showdetails',
  state: {
    data: [{name:"nginx",description:"good",url:"hello",id:1001}],
    counter: 0,
      },
  effects: {
    *getdetails({payload}, sagaEffects) {
    const { call, put } = sagaEffects;
    const endPointURI = payload;
    console.log("hhhhh");
	 // 加入 try catch 捕获抛错 listImages
    const puzzle = yield call(getDetails,payload);
    console.log(puzzle.info.data);
    yield put({ type: 'addNewCard', payload: puzzle.info.data });

  
    },
    *submitcomment({payload}, sagaEffects) {
    /*const { call, put } = sagaEffects;
    const endPointURI = payload;
    console.log("hhhhh");
   // 加入 try catch 捕获抛错 listImages
    const puzzle = yield call(getDetails,payload);
    console.log(puzzle.info.data);
    yield put({ type: 'addNewCard', payload: puzzle.info.data });*/
    console.log("the comment is ",payload);
    return {
    "status": "ok",
    "type": "image",
    "currentAuthority": "user",
    "info": {
        "success": true
    }
		};

  
    },
  },
  reducers: {
    addNewCard(state, { payload: newCard }) {
      //console.log("the new card is ",newCard);
      const nextCounter = state.counter + 1;
      //const newCardWithId = { ...newCard, id: nextCounter };
      //console.log("the newCardWithId",newCardWithId);
      state.data = [newCard];
      const nextData = state.data.concat(newCard);//list
      console.log("the nextdata is",nextData);
      return {
        data: newCard,
        counter: nextCounter,
      };
    }
  },
};